package com.kylin;

import com.kylin.dxfUtils.AnalyzeDXF;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.sql.*;
import java.util.ArrayList;


@SpringBootApplication
public class DxfAnalyzeApplication {

    public static void main(String[] args) {
        SpringApplication.run(DxfAnalyzeApplication.class, args);
        {
            Connection conn = null;
            PreparedStatement ps = null;
            ResultSet rs = null;
            final CallableStatement cs = null;
            AnalyzeDXF analyzeDXF = new AnalyzeDXF();
            ArrayList<DxfModel> cadObjects = analyzeDXF.dealDXF("/Users/wuxianwen/Desktop/dxfs/design.dxf");
            for (int i = 0; i < cadObjects.size(); i++) {
                DxfModel temp = cadObjects.get(i);
                String id = temp.getId();
                String type = temp.getType();
                String description = temp.getDescription();
                String xyz = temp.getXyz();
                conn = DBConn.conn();//调用 DBconnection 类的 conn() 方法连接数据库
                String sql = "INSERT INTO cad (id,type,description,xyz) VALUES(?,?,?,?)";
                try {
                    ps = conn.prepareStatement(sql);
                    ps.setString(1, id);
                    ps.setString(2, type);
                    ps.setString(3, description);
                    ps.setString(4, xyz);
                    ps.executeUpdate();
                    int num = i + 1;
                    System.out.println("插入第" + num + "条成功(*￣︶￣)");
                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    DBConn.close();
                }
            }
        }
    }
}
